<?php echo form_tag('component/save', array(
  'id'        => 'sf_admin_edit_form',
  'name'      => 'sf_admin_edit_form',
  'multipart' => true,
)) ?>

<?php echo object_input_hidden_tag($component, 'getId') ?>

<fieldset id="sf_fieldset_none" class="">

<div class="form-row">
  <?php echo label_for('component[productcode]', __($labels['component{productcode}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('component{productcode}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('component{productcode}')): ?>
    <?php echo form_error('component{productcode}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_input_tag($component, 'getProductcode', array (
  'size' => 25,
  'control_name' => 'component[productcode]',
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>

<div class="form-row">
  <?php echo label_for('component[description]', __($labels['component{description}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('component{description}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('component{description}')): ?>
    <?php echo form_error('component{description}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_input_tag($component, 'getDescription', array (
  'size' => 80,
  'control_name' => 'component[description]',
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>

<div class="form-row">
  <?php echo label_for('component[category]', __($labels['component{category}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('component{category}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('component{category}')): ?>
    <?php echo form_error('component{category}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

<!--Tien-->
<select name="component[category]" id="component_category" onchange="EnableMinQtyLevel()">
<?php
    $categorylist = CommonValues::$gCompCategory['key'];
    $category = $component->getCategory() ? $component->getCategory() : 0;
    foreach ($categorylist as $key => $value)
    { 
    	echo '<option value="' . $value.'" ';
    	if ($value == $category) 
    	   echo  'selected="selected" >';
    	else echo '>';
    	echo $key;
    	echo '</option>';
    }
?>
</select>


    </div>
</div>

<div class="form-row">
  <?php echo label_for('component[componenttype_id]', __($labels['component{componenttype_id}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('component{componenttype_id}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('component{componenttype_id}')): ?>
    <?php echo form_error('component{componenttype_id}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php 
  $value = object_select_tag($component, 'getComponenttypeId', array (
  'related_class' => 'ComponentType',
  'control_name' => 'component[componenttype_id]',
  'peer_method'=>   'getSorted',
)); 
   echo $value ? $value : '&nbsp;' 
?>
    </div>
</div>

<div class="form-row">
  <?php echo label_for('component[location]', __($labels['component{location}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('component{location}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('component{location}')): ?>
    <?php echo form_error('component{location}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_input_tag($component, 'getLocation', array (
  'size' => 80,
  'control_name' => 'component[location]',
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>

<div class="form-row">
  <?php echo label_for('component[brand]', __($labels['component{brand}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('component{brand}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('component{brand}')): ?>
    <?php echo form_error('component{brand}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_input_tag($component, 'getBrand', array (
  'size' => 80,
  'control_name' => 'component[brand]',
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>

<div class="form-row">
  <?php echo label_for('component[componentunit_id]', __($labels['component{componentunit_id}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('component{componentunit_id}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('component{componentunit_id}')): ?>
    <?php echo form_error('component{componentunit_id}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_select_tag($component, 'getComponentunitId', array (
  'related_class' => 'ComponentUnit',
  'control_name' => 'component[componentunit_id]',
  'peer_method'=>   'getSorted',
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>

<div class="form-row">
  <?php echo label_for('component[minstockqty]', __($labels['component{minstockqty}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('component{minstockqty}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('component{minstockqty}')): ?>
    <?php echo form_error('component{minstockqty}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <input type = "text" name ='component[minstockqty]' id ='component_minstockqty'  value ="<? echo $component->getMinstockqty()?>" <? if ($component->getCategory()!= CommonValues::$gCompCategory['key']['Sub Component']) echo " disabled"?> >
    </div>
</div>

</fieldset>

<?php 
echo link_to_remote('', array('update' => 'list_component', 
  'url' => 'component/listAjax', 
  'loading' => visual_effect('appear', 'indicator'),
  'complete' => visual_effect('fade', 'indicator'). visual_effect('highlight', 'list_component'),
  'position' => 'bottom',
));
?>
<script type="text/javascript">

function EnableMinQtyLevel(){
    var cate = $("component_category");    
    var gt = cate.options[cate.selectedIndex].value;
    var min = $('component_minstockqty');
    if (gt !=1) {                   
        min.value = '';     
        min.disabled=true;    
    } else min.disabled=false;    
}
</script>

<?php include_partial('edit_actions', array('component' => $component)) ?>

</form>

<ul class="sf_admin_actions">
      <li class="float-left"><?php if ($component->getId()): ?>
<?php echo button_to(__('delete'), 'component/delete?id='.$component->getId(), array (
  'post' => true,
  'confirm' => __('Are you sure?'),
  'class' => 'sf_admin_action_delete',
)) ?><?php endif; ?>
</li>
  </ul>
